$(function() {
    $("#user-edit-btn").click(function() {
        let username = $("#username").val();
        let password = $("#password").val();
        let headImage= $("#headImage").val();
        let emptyImage = (headImage == null || "" == headImage.trim());
        let emptyUsername = (username == null || "" == username.trim());
        let emptyPassword = (password == null || "" == password.trim());
        let suffix = headImage.substring(headImage.indexOf(".") + 1);
        let isImage = (['png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'psd', 'svg', 'tiff'].indexOf(suffix) != -1);
        if(emptyPassword) {
            $("#user-edit-errorMsg").text("Password is empty!");
        }
        if(emptyUsername) {
            $("#user-edit-errorMsg").text("User name is empty!");
        }
        if(emptyImage || !isImage) {
            $("#user-edit-errorMsg").text("Please select a head image!");
        }
        return !emptyPassword && !emptyUsername && !emptyImage && isImage;
    });
});